<?php
// No direct access
defined('_JEXEC') or die('Restricted access');

date_default_timezone_set('Australia/Sydney');

// Set the table directory
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');

//include the needed classes
require_once (JPATH_COMPONENT.DS.'classes'.DS.'ownservice.acl.php');
require_once (JPATH_COMPONENT.DS.'classes'.DS.'ownservice.php');

//include helper
require_once (JPATH_COMPONENT.DS.'helpers'.DS.'menu.helper.php');
require_once (JPATH_COMPONENT.DS.'helpers'.DS.'ownservice.helper.php');

require_once(JPATH_COMPONENT.DS.'classes'.DS.'fleximycontentpagination.php');

//Require the base controller
require_once(JPATH_COMPONENT.DS.'controller.php');

//Initialise variables
$user			= & JFactory::getUser();
$ownuser		= & Ownservice::getUser();

//get vars
$gid			= $user->gid;
$changepassword = $ownuser->get('changepassword');

if( ( $changepassword == 0 ) && ( $user->get('id') > 0 ) && ($gid < 25) ) {
	$controller = '';
} else {
	$controller = JRequest::getWord('controller');
}

// Require specific controller if requested
if( $controller ){
	$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
	if(file_exists($path)){
		require_once $path;
	} else {
		$controller = '';
	}
}

// Create the controller
$classname	= 'OwnserviceController'.ucfirst($controller);
$controller = new $classname( );

// Perform the Request task
$task = JRequest::getCmd('task');
if( ( $changepassword == 0 ) && ( $task != 'changepassword_save' ) && ($user->get('id') > 0) && ($gid < 25) ) {
	$controller->execute('changepassword');
} else {
	$controller->execute($task);
}

// Redirect if set by the controller
$controller->redirect();